package com.neusoft.databus.policy.repository.impl;

import java.util.List;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;

import com.neusoft.bizcore.web.jpa.repository.AbstractRepository;
import com.neusoft.bizcore.web.support.Searchable;
import com.neusoft.databus.policy.model.PolicyRefResource;
import com.neusoft.databus.policy.model.QPolicyRefResource;
import com.neusoft.databus.policy.repository.CustomizedPolicyRefResourceRepository;
import com.querydsl.core.BooleanBuilder;
import com.querydsl.jpa.impl.JPAQuery;

public class CustomizedPolicyRefResourceRepositoryImpl extends AbstractRepository
        implements CustomizedPolicyRefResourceRepository {

    @Override
    public Page<PolicyRefResource> search(Pageable pageable, Searchable searchable) {
        QPolicyRefResource qPolicyRefResource = QPolicyRefResource.policyRefResource;
        final BooleanBuilder where = new BooleanBuilder();
        where.and(super.containsStr(qPolicyRefResource.resourceCode, searchable, "resourceCode"));
        JPAQuery<PolicyRefResource> query = this.query().selectFrom(qPolicyRefResource).where(where);
        return super.search(query, pageable);
    }

    @Override
    public List<PolicyRefResource> search(Searchable searchable) {
        QPolicyRefResource qPolicyRefResource = QPolicyRefResource.policyRefResource;
        final BooleanBuilder where = new BooleanBuilder();
        where.and(super.containsStr(qPolicyRefResource.resourceCode, searchable, "resourceCode"));
        JPAQuery<PolicyRefResource> query = this.query().selectFrom(qPolicyRefResource).where(where);
        return query.fetch();
    }

    @Override
    protected Class<?> getModelClass() {
        return PolicyRefResource.class;
    }

}
